package zut.dao.impl;


import org.springframework.stereotype.Repository;
import zut.dao.LessonDao;
import zut.model.Lesson;
import zut.util.JDBCUtil;

import java.util.List;

@Repository
public class LessonDaoImpl implements LessonDao{

    public void add(String name, String password) {
        String sql="insert into lesson values ('name','password') ";
        JDBCUtil.daDMLWithSQL(sql,name,password);
    }


    public void delete(String name) {
        String sql="delete from user where name=?";
        JDBCUtil.daDMLWithSQL(sql,name);
    }


    public List<Lesson> selecAll() {

        String sql="select * from lesson";
        List<Lesson> list=JDBCUtil.dbDQLWithSQL(sql, Lesson.class);
        return list;
    }



    public Lesson selectByName(String name, String password) {
        String sql="select * from lesson where name=?and password=?";
        List<Lesson> lessons=JDBCUtil.dbDQLWithSQL(sql,Lesson.class,name,password);
        if(!lessons.isEmpty()&&lessons.size()>0){
            return lessons.get(0);
        }
        else {
            return null;
        }
    }


    public void update(Lesson lesson) {
        String sql="update lesson set password=?,lessonname=?,starttime=?stoptime=?," +
                "nickname=?where name=?";
        JDBCUtil.daDMLWithSQL(sql,lesson.getPassword(),lesson.getLessonname(),lesson.getStarttime(),lesson.getStoptime(),lesson.getNickname(),lesson.getName());
    }


    }



